package simple;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;

//客户端管道处理
public class NettyClientHander extends ChannelInboundHandlerAdapter {
    //通道就绪
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("clien :" + ctx);
        ctx.writeAndFlush(Unpooled.copiedBuffer("hello,server:(>^w^<)", CharsetUtil.UTF_8));
    }
    //读取事件
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf buf = (ByteBuf)msg;
        System.out.println("服务器回复信息："+buf.toString(CharsetUtil.UTF_8));
    }
}
